package com.gjx.clock

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.gjx.clock.dao.RestClockDao
import com.gjx.clock.dao.NormalClockDao
import com.gjx.clock.entity.NormalAlarmClock
import com.gjx.clock.entity.RestAlarmClock


@Database(version = 1, entities = [RestAlarmClock::class,NormalAlarmClock::class])
abstract class AppDatabase : RoomDatabase() {
    abstract fun restClockDao(): RestClockDao
    abstract fun normalClockDao(): NormalClockDao
    companion object {
        private var instance: AppDatabase? = null
        @Synchronized
        fun getDatabase(context: Context): AppDatabase {
            instance?.let {
                return it
            }
            return Room.databaseBuilder(context.applicationContext,
                AppDatabase::class.java, "app_database")
                .allowMainThreadQueries() // 允许在主线程进行数据库操作,用于测试时
                .build().apply {
                    instance = this
                }
        }
    }
}